<script setup>
import { onMounted, ref } from "vue";
import { getCompanyById } from "../api/company";
import {updateCompany} from "../api/company"
import { useRoute } from "vue-router";

let router =  useRoute()
let companyId = router.params.id
console.log("获得的id是" + companyId)

let company = ref({}) //加{}变成对象形式，什么时候要加什么时候不加

onMounted(()=>{
    getCompany();
})

async function getCompany() {
    const response = await getCompanyById(companyId)
    console.log(response)
    company.value = response.data.data //为company赋值
}

async function EditCompany() {
    console.log("调用了修改方法")
    const response = await updateCompany(company.value)
    console.log("修改时候的response:",response)
    if( response.data.code === 200){
        confirm("修改成功！")
    }else{
        confirm("修改失败！")
    }

}
</script>

<template>
    <div>
        <form @submit.prevent="EditCompany">
                     <input type="hidden" v-model="company.companyId">
            公司名称: <input type="text" v-model="company.companyName"><br/>
            公司邮箱: <input type="email" v-model="company.companyEmail"><br/>
            公司电话: <input type="text" v-model="company.companyPhone"><br/>
            公司城市: <input type="text" v-model="company.companyCity"><br/>
            公司类型: <input type="text" v-model="company.companyIndustry"><br/>
            公司规模: <input type="text" v-model="company.companySize"><br/>
            公司状态: <input type="text" v-model="company.companyStatus"><br/>
            公司网址: <input type="text" v-model="company.companyWebsite"><br/>
            <button type="submit">修改</button>
        </form>
    </div>
</template>